package com.apartment.dao;

import com.apartment.data.entity.Admin;
import com.apartment.data.entity.Indent;
import com.apartment.data.view.Indentview;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Author : xuzhiyong
 * Date : 2022/5/27 17:51
 */
public interface OrderDao extends JpaRepository<Indent, Integer> {

//    SELECT a.id,a.username,a.password from Admin a where a.username like ?1
    @Query(value = "SELECT i.id,i.begintime,i.endtime,i.pay_status,i.user_id,i.apartment_id from Indent i where i.user_id= ?1",nativeQuery = true)
    List<Indent> findIndentsByUserId(Integer id);

    @Query(value = "select i.id,i.begintime,i.endtime,i.pay_status,u.id as user_id,u.username as user_username,u.phone as user_phone,a.id as apartment_id from Indent i,User u,Apartment a where i.user_id=?1 and i.user_id = u.id ",nativeQuery = true)
    List<Indent> findIndentByUserId(Integer id);

    List<Indentview> findIndentviewByUserId(Integer id);
}
